#pragma once

#ifndef VTTINFOFILE_H
#define VTTINFOFILE_H

#include "VTTObject.h"
#include "VTTCommon.h"

#include <array>
#include <map>
#include <string>
#include <vector>

/**
  *	Struct that stores all areas, where the image occurs in the Atlas as well as the time stamp
  * when the image was changed the last time
  */
struct VTTImageInfo
{
	/** vector with all areas, where the image occurs in the Atlas. Each area is an array with four elements in the order x_min, y_min, x_max + 1, y_max + 1 */
	std::vector<std::tr1::array<UINT32, 4>> areas;
	/** time stamp when the image was changed the last time*/
	struct tm changeTime;
};

class VTTImage;

/**
  *	Info File objects store the whole information that is needed to find a specific
  * image inside the Virtual Texture Atlas. This is especially necessary when
  * the Atlas is updated after an image has changed.
  */
class VTTInfoFile : public VTTObject
{
public:

	VTTInfoFile( const std::string &fileName );

	const std::map<std::string, struct VTTImageInfo> &GetNamesToInfoMap( void ) const;
	bool SetChangeTimeForImageName( const std::string &imageName, const struct tm &imageInfo );

	bool LoadFromFile( const std::string &filePath );
	bool WriteToFile( const std::string &filePath = "" ) const;

	static bool WriteInitialFile( const std::string &directoryPath, const std::map<std::string, VTTImage*> *imageNamesToImagesMap );

private:
	/** Path of the directory, where all the images of the Atlas reside. This is also the directory where the Atlas and Tile Store directories are. */
	std::string mBasePath;
	/** Path of the info file */
	std::string mFullPath;
	/** Map, that maps names (not paths!) of images to the info-structs. So it is possible to find all occurrences of a single image inside the Atlas as well as the time when the image was changed the last time */
	std::map<std::string, struct VTTImageInfo> mNamesToInfoMap;

	void Reset( void );
};
#endif